What is semver-diff?
The semver-diff npm package is a utility for comparing two semantic version numbers and determining the type of version difference between them. It can identify whether the change is a major, minor, patch, pre-release, or build difference.
What are semver-diff's main functionalities?
Version difference identification
This feature allows you to compare two semantic version numbers and determine the type of change. The code sample demonstrates how to use semver-diff to compare versions '1.0.0' and '2.0.0', which would log 'major' as the type of version difference.
"use strict";
const semverDiff = require('semver-diff');
const diffType = semverDiff('1.0.0', '2.0.0');
console.log(diffType); // 'major'"
Other packages similar to semver-diff
semver
The semver package is a more comprehensive semantic version parser and utility. It includes functions for parsing, comparing, and incrementing version numbers, as well as determining version precedence. Compared to semver-diff, semver offers a broader set of tools for working with semantic versions beyond just identifying the difference between two versions.
compare-versions
Compare-versions is a simple utility for comparing and sorting semantic version numbers. It provides a straightforward API for comparing version strings and determining their order. While semver-diff specifically identifies the type of version difference, compare-versions focuses on comparison and sorting without categorizing the type of change.
semver-diff
Get the diff type of two semver versions: 0.0.1 0.0.2
→ patch
Install
$ npm install semver-diff
Usage
import semverDiff from 'semver-diff';
semverDiff('1.1.1', '1.1.2');
semverDiff('1.1.1-foo', '1.1.2');
semverDiff('0.0.1', '1.0.0');
semverDiff('0.0.1-foo', '1.0.0');
semverDiff('0.0.1', '0.1.0');
semverDiff('0.0.1-foo', '0.1.0');
semverDiff('0.0.1-foo', '0.0.1-foo.bar');
semverDiff('0.1.0', '0.1.0+foo');
semverDiff('0.0.1', '0.0.1');
semverDiff('0.0.2', '0.0.1');
API
semverDiff(versionA, versionB)
Returns the difference type between two semver versions, or undefined
if they are identical or the second one is lower than the first.
Possible values:
'major'
,'premajor'
,'minor'
,'preminor'
,'patch'
,'prepatch'
,'prerelease'
,'build'
,undefined
Related
- latest-semver - Get the latest stable semver version from an array of versions
- to-semver - Get an array of valid, sorted, and cleaned semver versions from an array of strings
- semver-regex - Regular expression for matching semver versions
- semver-truncate - Truncate a semver version:
1.2.3
→ 1.2.0